export const useUserPinia = defineStore('user', {
  state: () => ({
    token: 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIzMzc4MzEiLCJleHAiOjE3MjQyMDI2MzAsImNyZWF0ZWQiOjE3MjE2MTA2MzA5NzgsInVzZXJuYW1lIjoiMTUwNTUyMTA5NzMifQ.wu20KhyAV7v5fzWGnBCSmULkBTULcEEC1rORted9ToCoLBbf80EKxoutfnqhQfQHtUzb_RyD63VjkzP3SrZXgw',
    nanoid: 1000,
    userinfo: {
      ok: '我是store',
    },
  }),
  getters: {
    getToken: state => state.token,
    getNanoid: state => state.nanoid,
  },
  actions: {
    setToken(value) {
      this.token = value
    },
    setNanoid() {
      this.nanoid += 10
    },
    logOutClear() {
      this.token = undefined
    },
  },
  persist: [
    {
      paths: [],
      storage: persistedState.localStorage,
    },
    {
      paths: ['token', 'nanoid'],
      storage: persistedState.cookiesWithOptions({ maxAge: 604800 }),
    },
  ],
})
